/*
 * @Author: LiJia
 * @Date: 2021-03-09 01:24:07
 * @LastEditTime: 2021-04-05 14:00:53
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \class-manage-system\miniprogram\pages\components\signin-item\signin-item.ts
 */

const app = getApp<IAppOption>()

Component({
  properties: {
    item: {
      type: Object,
      value: {}
    },
    index: {
      type: Number,
      value: 0
    }
  },
  data: {
    currentPage: 'minePage'
  },

  // 组件实例化，但节点树还未导入，因此这时不能用setData
  created() {},

  // 节点树完成，可以用setData渲染节点，但无法操作节点
  attached() {},

  // 组件布局完成，这时可以获取节点信息，也可以操作节点
  ready() {},

  // 组件实例被移动到树的另一个位置
  moved() {},

  // 组件实例从节点树中移除
  detached() {},

  methods: {
    // 这里放置自定义方法
    /**
     * 点击签到按钮执行
     */
    handleSignin() {
      let that = this
      const apiUrl = wx.getStorageSync('apiUrl')
      wx.request({
        url: apiUrl + '/signin',
        data: {
          studentID: (app.globalData.clsUserInfo as any).id,
          signinID: this.data.item.id
        },
        success: (res) => {
          debugger
          let _res = res.data as any
          if (_res.code === 200) {
            let itemIsSignin = 'item.isSignin'
            that.setData({
              [itemIsSignin]: true
            })
          } else {
            wx.showToast({
              title: _res.msg,
              icon: 'none',
              duration: 2021
            })
          }
        }
      })
    }
  }
})

export default {}
